package com.zw.yzk.kabu.mapper;


import com.zw.yzk.kabu.data.network.entity.CosplayListEntity;
import com.zw.yzk.kabu.model.CosplayModel;
import com.zw.yzk.kabu.utils.TimeFormatUtils;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by zhanwei on 2016/12/24.
 */

public class CosplayListMapper {

    @Inject
    public CosplayListMapper() {

    }

    public CosplayModel transfer(CosplayListEntity.Item item) {
        CosplayModel model = new CosplayModel();
        model.setId(item.id);
        model.setPublisher(item.publisher);
        model.setPublisherHeadUrl(item.publishHeadUrl);
        //model.setPublishTime(item.publishTime);
        try {
            model.setPublishTime(TimeFormatUtils.getTimeInterval(item.publishTime, "yyyy-MM-dd HH:mm:ss"));
        } catch (Exception e) {
            model.setPublishTime(item.publishTime);
        }
        model.setPublishAddress(item.publishAddress);
        model.setMessage(item.message);
        model.setCosUrl(item.imageUrl);
        model.setPraiseCount(item.praiseCount);
        model.setPraise(item.isPraised);
        model.setCollected(item.collect);
        model.setCommentCount(item.commentCount);
        model.setPublisherId(item.publisherId);
        model.setCompetition(item.isCompetition == 1);

        return model;
    }

    public List<CosplayModel> transfer(CosplayListEntity entity) {
        List<CosplayModel> modelList = new ArrayList<>();
        if (entity.result.cosplayList == null || entity.result.cosplayList.isEmpty()) {
            return modelList;
        }
        for (CosplayListEntity.Item item : entity.result.cosplayList) {

            modelList.add(transfer(item));
        }
        return modelList;
    }
}
